package com.hxzy.config;

import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.strategy.SaStrategy;
import com.hxzy.common.aspect.satoken.StpMobileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.AnnotatedElementUtils;

@Configuration
public class SaTokenConfigure {

    @Autowired
    public void rewriteSaStrategy() {
        // 重写Sa-Token的注解处理器，增加注解合并功能
        SaStrategy.instance.getAnnotation = (element, annotationClass) -> {
            return AnnotatedElementUtils.getMergedAnnotation(element, annotationClass);
        };
    }

    /**
     * 为 StpUserUtil 注入 StpLogicJwt 实现
     */
    @Autowired
    public void setUserStpLogic() {
        StpMobileUtil.setStpLogic(new StpLogicJwtForSimple(StpMobileUtil.TYPE));
    }


}
